
from model import StudentModel

class StudentController:
    """
        学生控制器：负责管理所有学生，提供核心功能.
    """

    def __init__(self):
        self.__list_student = []
        self.start_id = 1001

    @property
    def list_student(self):
        return self.__list_student

    def add_student(self,new_stu):
        # 自增长
        new_stu.sid = self.start_id
        self.start_id += 1
        self.__list_student.append(new_stu)

    def remove_student(self, sid):
        for i in range(len(self.__list_student)):
            if self.__list_student[i].sid == sid:
                del self.__list_student[i]
                return True
        return False # 如果没有找到则删除失败

    def update_student(self, stu):
        for item in self.__list_student:
            if item.sid == stu.sid:
                item.__dict__ = stu.__dict__
                return True
        return False
        # for i in range(len(self.list_student)):
        #     if self.list_student[i].sid == stu.sid:
        #         self.list_student[i].name = stu.name
        #         self.list_student[i].age = stu.age
        #         self.list_student[i].score = stu.score

# 测试代码
if __name__ == "__main__":
    controller = StudentController()
    controller.add_student(StudentModel())
    controller.add_student(StudentModel())
    controller.add_student(StudentModel())
    for item in controller.list_student:
        print(item)